package 常用API类;

public class Main {
    public static void main(String[] args) { //  length
        String name = "我爱你中国love";
        System.out.println(name.length());

        char c1 = name.charAt(1);//   charAt
        System.out.println(c1);

        System.out.println("===============遍历字符串=================");
        for (int i = 0; i < name.length(); i++) {
            char c = name.charAt(i);
            System.out.println(c);
        }


        char[] arr = name.toCharArray();  //  toCharArray
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]);
        }
        System.out.println();


        String name2 = "C语言是编程语言之母";
        System.out.println(name2.substring(0, 8)); //substring 包前不包后

        System.out.println(name2.substring(4));

        String name3 = "XXX很摆，XXX是摆烂之王";
        String rs = name3.replace("XXX","***"); //  replace
        System.out.println(rs);


        System.out.println(name3.replace("XXX","***").contains("***"));//contains
        System.out.println(name3.contains("XXX"));

        System.out.println(name3.startsWith("XXX"));//  startsWith


        String name4 = "a1,b2,c3,d4";
        String[] strings = name4.split(",");//  split
        for (int i = 0; i < strings.length; i++) {
            System.out.println("选择了:"+strings[i]);
        }
    }
}